<template>
  <div class="travel-route">
    <div class="route-box">
      <ul>
        <li v-for="item in list" :key="item.route_id">
          <div class="routes-img" @click="goDetail(item.route_id)">
            <img :src="require(`@/assets/images/${item.view_pic}`)" alt="">
          </div>
          <div class="routes-cont">
            <p>{{ item.title }}</p>
            <h5>{{ item.intro }}</h5>
            <div class="routes-unit">
              <span><i class="iconfont icon-dianzan"></i><b>{{ item.support }}</b></span>
              <span><i class="iconfont icon-icon-"></i><b>{{ item.seeNum }}</b></span>
            </div>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: []
    }
  },
  created() {
    this.getRouteData()
    console.log(this.list)
  },
  methods: {
    getRouteData() {
      //此时相当于访问 http://localhost:8080/data/scenic.json
      this.$axios
        .get('/data/route.json')
        .then((response) => {
          let { status, data } = response
          if (+status !== 200) return
          this.list = data
        })
        .catch((error) => {
          console.log(error)
        })
    },
    goDetail(id) {
      this.$router.push(`/routesDetail?id=${id}`)
    }
  }
}
</script>

<style scoped>
.route-box {
  max-width: 1200px;
  margin: 0 auto;
  margin-top: 20px;
}
.route-box > ul {
  display: flex;
  flex-wrap: wrap;
  margin-left: -30px;
}
.route-box > ul li {
  width: 30.8%;
  height: 450px;
  border-radius: 3px;
  background-color: #fff;
  margin-bottom: 50px;
  margin-left: 30px;
  overflow: hidden;
  box-shadow: 1px 2px 3px #dbdbdb;
  transition: all 0.5s;
}
.route-box > ul li:hover {
  box-shadow: 0 1px 7px 5px rgba(0, 0, 0, 0.1);
  transform: translateY(-3px);
}
.route-box > ul li .routes-img {
  width: 100%;
  height: 70%;
  overflow: hidden;
  cursor: pointer;
}
.route-box > ul li .routes-img img {
  width: 110%;
  height: 110%;
}
.route-box > ul li .routes-cont {
  position: relative;
  height: 30%;
  padding: 10px 10px 0;
}
.route-box > ul li .routes-cont p {
  font-size: 16px;
  line-height: 30px;
  color: brown;
}
.route-box > ul li .routes-cont h5 {
  font-size: 14px;
  font-weight: normal;
  color: #666;
}
.route-box > ul li .routes-cont .routes-unit {
  position: absolute;
  right: 15px;
  bottom: 10px;
}
.route-box > ul li .routes-cont .routes-unit .icon-dianzan {
  cursor: pointer;
}
.route-box > ul li .routes-cont .routes-unit b {
  display: inline-block;
  width: 23px;
  margin-left: 2px;
  font-weight: normal;
  font-size: 14px;
  color: #666;
}

/* 移动端样式 */
@media screen and (max-width: 767px) {
  .route-box {
    margin-top: 0;
    padding-top: 10px;
  }

  .route-box > ul {
    justify-content: center;
  }
  .route-box > ul li {
    width: 75%;
    height: 90vw;
  }

  .route-box > ul li .routes-cont p {
    font-size: 12rem;
  }
  .route-box > ul li .routes-cont h5 {
    font-size: 10rem;
    line-height: 5vw;
  }

  .route-box > ul li .routes-cont .routes-unit b {
    font-size: 10rem;
  }
}

/* 平板端样式 */
@media screen and (min-width: 768px) and (max-width: 1155px) {
  /* 在此处编写平板端样式 */
  .route-box > ul {
    justify-content: space-around;
  }
  .route-box > ul li {
    width: 43%;
    height: 50vw;
  }
}
</style>